/** 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.free.i.virtual.machine.hal.devicealias.echo;

import it.free.i.virtual.swarm.ComposableInformationUnit;
import it.free.i.virtual.swarm.ComposableInformationUnit.CIUGeneratorAllowedOperations;
import it.free.i.virtual.machine.hal.devicealias.command.DeviceAliasPortCommand;

import java.util.Date;

/**
 * Default implementation for the actuator invocation feedback
 * @author stefano
 */
public class ActuatorInvocationFeedBackEchoImpl implements ActuatorInvocationFeedBackEcho {

	private String invokedActuatorName = null;
	private long valueWritten = 0L;
	private Date timeStamp = null;
	private DeviceAliasPortCommand actuatorInvocation = null;
	
	public ActuatorInvocationFeedBackEchoImpl(){
		timeStamp = new Date();
	}
	
	/* (non-Javadoc)
	 * @see it.free.i.virtual.machine.hal.devicealias.echo.ActuatorInvocationFeedBackEcho#setInvokedActuatorName(java.lang.String)
	 */
	public void setInvokedActuatorName(String name) {
		this.invokedActuatorName = name;
	}

	/* (non-Javadoc)
	 * @see it.free.i.virtual.machine.hal.devicealias.echo.ActuatorInvocationFeedBackEcho#setValueWrittenOnActuator(long)
	 */
	public void setValueWrittenOnActuator(long valueWritten) {
		this.valueWritten = valueWritten;
	}

	/* (non-Javadoc)
	 * @see it.free.i.virtual.machine.hal.devicealias.echo.Echo#getTimeStamp()
	 */
	public Date getTimeStamp() {
		return this.timeStamp;
	}

	public String getInvokedActuatorName() {
		return this.invokedActuatorName;
	}
	
	public long getValueWrittenOnActuator() {
		return this.valueWritten;
	}

	/**
	 * Provide this object transformed into a composable information unit
	 */
	public ComposableInformationUnit getRenderedObjectImage() {
	
		ComposableInformationUnit composableInformationUnit = ComposableInformationUnit.Factory.createObject();
			
		composableInformationUnit.setAttribute("invokedActuatorName", this.invokedActuatorName);
		composableInformationUnit.setAttribute("valueWritten", this.valueWritten);
		composableInformationUnit.setAllowedOperations(CIUGeneratorAllowedOperations.READ_AND_WRITE);
		composableInformationUnit.setOperation(this.actuatorInvocation);
			
		composableInformationUnit.setCiuType(this.getClass().getName());
		
		return composableInformationUnit;
	}

	/**
	 * @return the actuatorInvocation
	 */
	public DeviceAliasPortCommand getActuatorInvocation() {
		return this.actuatorInvocation;
	}

	/**
	 * @param actuatorInvocation the actuatorInvocation to set
	 */
	public void setActuatorInvocation(DeviceAliasPortCommand actuatorInvocation) {
		this.actuatorInvocation = actuatorInvocation;
	}
}
